<template>
  <div class="user" style="padding: 0px;">
    <el-card>
      <el-button size="small" @click="onExport">导出发票</el-button>
      <el-table size="small" :data="tableData" border style="width: 100%;margin-top:10px;" v-loading="loading" stripe>
        <el-table-column prop="code" fixed label="发票编号" width="200"></el-table-column>
        <el-table-column prop="orderNo" label="销售订单号" width="180">
          <template #default="scope">
            <a @click="orderNoToPage(scope.row)" href="javascript:;">{{ scope.row.orderNo }}</a>
          </template>
        </el-table-column>
        <el-table-column prop="typeText" label="抬头类型" width="150"></el-table-column>
        <el-table-column prop="rise" label="公司抬头" width="200"></el-table-column>
        <el-table-column prop="duty" label="公司税号" width="200"></el-table-column>
        <el-table-column prop="allMoney" label="开票金额" width="150"></el-table-column>
        <el-table-column prop="address" label="公司地址" width="200"></el-table-column>
        <el-table-column prop="phone" label="公司电话" width="200"></el-table-column>
        <el-table-column prop="bank" label="开户银行" width="240"></el-table-column>
        <el-table-column prop="account" label="开户账号" width="200"></el-table-column>
        <el-table-column prop="email" label="电子邮箱" width="180"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <el-icon v-if="scope.row.status === 0" style="font-size: 20px;color:green">
              <Check />
            </el-icon>
            <el-icon style="font-size: 20px;color:red" v-else>
              <Close />
            </el-icon>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template #default="scope">
            <el-button @click="deleteClick(scope.row)" type="text" size="small">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination style="float:right;margin-top:10px;margin-bottom:10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper" :total="totalDataNumber"></el-pagination>
    </el-card>
  </div>
</template>

<script>
import StoreApi from "@/api/store.js";
export default {
  components: {},
  inject: ["reload"],
  data() {
    return {
      /*是否加载完成*/
      loading: false,
      /*列表数据*/

      tableData: [

      ],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*横向表单数据模型*/
      formInline: {
        user: "",
        region: "",
      },
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    orderNoToPage(row) {
      let self = this;
      let params = row.orderId;
      self.$router.push({
        path: "/order/order/Detail",
        query: {
          id: params,
          tk: 'view',
          type: 'FP'
        },
      });
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getTableList();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {};
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      self.loading = true
      StoreApi.getInvoice(Params, true)
        .then((res) => {
          self.loading = false;
          self.tableData = res.data.records;
          self.totalDataNumber = res.data.total;
        })
        .catch((error) => { });
    },

    /*打开添加*/
    addClick() {
      this.$router.push("/store/store/add");
    },
    onExport() {
      StoreApi.exportInvoice()
        .then(res => {
          const blob = new Blob([res], { type: 'application/vnd.ms-excel' })
          const url = window.URL.createObjectURL(blob)
          const a = document.createElement('a')
          a.href = url
          const fdate = new Date()
          const perx = `${fdate.getFullYear()}-${fdate.getMonth() + 1}-${fdate.getDate()}`
          a.download = perx + '发票列表.xlsx'
          a.click()
          setTimeout(() => {
            a.remove()
          }, 1000)
        })
    },


    /*删除*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          StoreApi.deleteInvoice(row.id, true)
            .then((data) => {
              ElMessage({
                message: "恭喜你，发票删除成功",
                type: "success",
              });
              self.getTableList();
            })
            .catch((error) => { });
        })
        .catch(() => { });
    },
  },
};
</script>

<style scoped>
::v-deep(.el-scrollbar__bar.is-horizontal) {
  height: 20px;          /* 想多粗就写多大 */
}
</style>